﻿using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbAdvancedMoviePreviewTest and is intended
    ///     to contain all TmdbAdvancedMoviePreviewTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbAdvancedMoviePreviewTest
    {
        /// <summary>
        ///     A test for TmdbAdvancedMoviePreview Constructor
        /// </summary>
        [TestMethod]
        public void TmdbAdvancedMoviePreviewConstructorTest()
        {
            var target = new TmdbAdvancedMoviePreview();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for IsAdult
        /// </summary>
        [TestMethod]
        public void IsAdultTest()
        {
            var target = new TmdbAdvancedMoviePreview(); 
            bool expected = new Random().Next( 0, Int32.MaxValue ) % 2 == 0;
            target.IsAdult = expected;
            bool actual = target.IsAdult;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Popularity
        /// </summary>
        [TestMethod]
        public void PopularityTest()
        {
            var target = new TmdbAdvancedMoviePreview();
            double expected = new Random().Next(0, Int32.MaxValue) * 2.121;
            target.Popularity = expected;
            double actual = target.Popularity;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem(@"..\..\TestData\advancedMoviePreview.json.txt")]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbAdvancedMoviePreview();
            var jsonContent = File.ReadAllText("advancedMoviePreview.json.txt");
            var actual = await target.DeserializeJson<TmdbAdvancedMoviePreview>(jsonContent);

            Assert.AreEqual(68726, actual.Id);
            Assert.AreEqual("Pacific Rim", actual.OriginalTitle);
            Assert.AreEqual("/sCJEwEShZvruTpQ2a4yiX3Q9EyZ.jpg", actual.PosterPath);
            Assert.AreEqual("2013-07-12", actual.ReleaseDate);
            Assert.AreEqual("Pacific Rim", actual.Title);
            
            Assert.AreEqual("/bCJLxmgNaZtpMyWKCCiTYrf3YOT.jpg", actual.BackdropPath);
            Assert.AreEqual(6.5, actual.VoteAverage);
            Assert.AreEqual(113, actual.VoteCount);

            Assert.AreEqual(47.6963716591165, actual.Popularity);
            Assert.AreEqual(false, actual.IsAdult);
        }
    }
}